#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
邮箱演示系统启动脚本
Email Demo System Startup Script

这个脚本用于启动Flask应用程序
This script is used to start the Flask application
"""

import os
import sys
from app import create_app

def main():
    """
    主函数：创建并运行Flask应用
    Main function: Create and run Flask application
    """
    try:
        # 创建Flask应用实例
        app = create_app()
        
        # 获取配置
        host = app.config.get('HOST', '127.0.0.1')
        port = app.config.get('PORT', 5000)
        debug = app.config.get('DEBUG', True)
        
        print("=" * 60)
        print("邮箱演示系统 - Email Demo System")
        print("=" * 60)
        print(f"🚀 启动服务器...")
        print(f"📍 地址: http://{host}:{port}")
        print(f"🔧 调试模式: {'开启' if debug else '关闭'}")
        print(f"📁 工作目录: {os.getcwd()}")
        print("=" * 60)
        print("💡 提示:")
        print("   - 默认管理员账号: admin")
        print("   - 默认管理员密码: admin123")
        print("   - 按 Ctrl+C 停止服务器")
        print("=" * 60)
        
        # 启动应用
        app.run(
            host=host,
            port=port,
            debug=debug,
            threaded=True,
            use_reloader=debug
        )
        
    except KeyboardInterrupt:
        print("\n👋 服务器已停止")
        sys.exit(0)
    except Exception as e:
        print(f"❌ 启动失败: {str(e)}")
        sys.exit(1)

if __name__ == '__main__':
    main()